package com.jdls.tanhua.web;

import com.jdls.tanhua.pojo.UserInfo;
import com.jdls.tanhua.server.MessagesServer;
import com.jdls.tanhua.vo.PageResult;
import com.jdls.tanhua.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 嘉德罗斯
 * @date 2021/10/30
 */
@RestController
@RequestMapping("/messages")

public class MessagesWeb {

    @Autowired
    private MessagesServer messagesServer;


    @GetMapping("/userinfo")
    public ResponseEntity userInfo(String huanxinId){
        UserInfoVo vo = messagesServer.userInfo(huanxinId);
        return ResponseEntity.ok(vo);
    }

    @PostMapping("/contacts")
    //添加好友
    public ResponseEntity contacts(@RequestBody Map map){
        Long userId = Long.valueOf((map.get("userId").toString()));
        messagesServer.contacts(userId);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/contacts")
    //查看好友列表
    public ResponseEntity findAll(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pagesize,
                                  String keyword){
        PageResult pageResult= messagesServer.findAll(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("/{type}")
    //查询点赞,评论或喜欢列表
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize,
                                @PathVariable String type){

        PageResult pageResult= messagesServer.type(page,pagesize,type);
        return ResponseEntity.ok(pageResult);

    }


    @GetMapping("/announcements")
    //查询公告列表
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){

        PageResult pageResult = messagesServer.announcements(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
}
